<template>
  <div class="app-container">
    <!-- 公共操作 star -->
    <breadcrumb class="margin-xs" />
    <!-- 公共操作 end -->
    <!-- 检索 start -->
    <el-filter
      size="medium"
      :data="filterInfo.data"
      :field-list="filterInfo.fieldList"
      :show-selection="false"
      :list-type-info="listTypeInfo"
      @handleFilter="handleFilter"
      @handleReset="handleReset"
      @handleEvent="handleEvent"
    />
    <!-- 检索 end -->
    <batch-menu @handleCreate="handleCreate" @handleDeleteAll="handleDeleteAll" @ExcelImport="ExcelImport" @ExcelExport="ExcelExport" />

    <!-- 数据列表 start -->
    <fire-table
      ref="table"
      :list="list"
      :total="total"
      :list-loading="listLoading"
      :columns="tableColumns"
      :list-query="filterInfo.data"
      @getList="getList"
      @handleSelectionChange="handleSelectionChange"
    >
      <template slot="breakfast" slot-scope="{ row }">
        {{
          row.breakfast === 0 ? "无早" : row.breakfast === 1 ? "单早" : "双早"
        }}
      </template>
      <template slot="free_cancel" slot-scope="{ row }">
        {{ row.free_cancel === 0 ? "否" : "是" }}
      </template>
      <template slot="action" slot-scope="{ row, index }">
        <el-button
          type="primary"
          size="mini"
          style="margin-right: 10px"
          @click="amend(row, index)"
        >修改</el-button>

        <el-button
          type="primary"
          size="mini"
          style="margin-right: 10px"
          @click="status(row, index)"
        >房态维护</el-button>

        <el-button
          type="primary"
          size="mini"
          style="margin-right: 10px"
          @click="price(row, index)"
        >房价维护</el-button>

        <el-popconfirm
          confirm-button-text="确认"
          cancel-button-text="取消"
          icon="el-icon-info"
          icon-color="red"
          title="确认删除吗?"
          @confirm="delectRow(row, index)"
        >
          <el-button slot="reference" type="danger" size="mini">删除</el-button>
        </el-popconfirm>
      </template>
    </fire-table>
    <!-- 数据列表 end -->
  </div>
</template>

<script>
import { roomIndex, roomDelete } from '@projectName/views/diandi_place/api/room/room'
export default {
  components: {},
  data() {
    return {
      dialogFormVisible: false,
      // 表格数据 start
      tableColumns: [
        { label: '排序', prop: 'displayorder' },
        {
          'label': '品牌',
          'prop': 'bloc.business_name'
        }, {
          'label': '店铺',
          'prop': 'store.name'
        },
        { label: '房间名称', prop: 'title' },
        { label: '面积', prop: 'area' },
        { label: '楼栋ID', prop: 'hotel_id' },
        { label: '是否显示具体位置', width: 140, prop: 'area_show' },
        { label: '床位数', prop: 'bed' },
        { label: '是否添加床位', width: 120, prop: 'bed_show' },
        { label: '是否可加床', width: 120, prop: 'bedadd' },
        { label: '是否显示添加床位', width: 140, prop: 'bedadd_show' },
        { label: '早餐', prop: 'breakfast', slot: 'breakfast' }, // 0无早 1单早 2双早
        { label: '入住开始时间', width: 120, prop: 'checkIn_start' },
        { label: '入住结束时间', width: 120, prop: 'checkIn_end' },
        { label: '现价', prop: 'cprice' },
        { label: '服务设施', prop: 'device' },
        { label: '楼层', prop: 'floor' },
        { label: '是否显示楼层', width: 120, prop: 'floor_show' },
        {
          label: '是否免费取下',
          width: 120,
          prop: 'free_cancel',
          slot: 'free_cancel'
        }, // 1是0否
        { label: '是否显示', prop: 'isshow' },
        { label: '语言类型标志/默认中文0', width: 170, prop: 'lanuage' },
        { label: '会员价', prop: 'mprice' },
        { label: '原价', prop: 'oprice' },
        { label: '退房时间', prop: 'out_time' },
        { label: '最多容纳人数', width: 120, prop: 'persons' },
        { label: '是否显示添加人数', width: 140, prop: 'persons_show' },
        { label: '几室', prop: 'room_num' },
        { label: '销售数量', prop: 'sales' },
        { label: '订房积分', prop: 'score' },
        { label: '是否显示抽烟', width: 120, prop: 'smoke_show' },
        { label: '房间状态', prop: 'status' },
        // { label: '房间主图', prop: 'thumb' },
        // { label: '房间相册', prop: 'thumbs' },
        { label: '几卫', prop: 'toilet_num' },
        {
          label: '操作',
          slot: 'action',
          fixed: 'right',
          width: 370
        }
      ],
      // 表格数据end
      // 检索 start
      filterInfo: {
        data: {
          page: 1,
          pageSize: 10
        },
        fieldList: [
          {
            label: '房间名称',
            type: 'input',
            value: 'HotelRoomSearch[title]'
          }
        ]
      },
      listTypeInfo: {},
      total: 0,
      list: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleSelectionChange(val) {
      console.log('传递来的', val)
    },
    handleRequestSuccess() {},
    selectType(val) {
      console.log(val)
    },
    getList() {
      const that = this
      that.listLoading = true
      roomIndex(that.filterInfo.data).then((response) => {
        that.total = response.data.dataProvider.total
        that.list = response.data.dataProvider.allModels
        console.log('列表数据层级测试', that.list)
        that.listLoading = false
      })
    },
    //  搜索
    handleFilter(row) {
      const that = this
      console.log(row)
      that.$set(that.filterInfo, 'data', row)
      console.log('检索前', that.filterInfo.data)
      that.getList()
    },
    handleReset(row) {
      this.getList()
    },
    handleEvent(row) {
      console.log(row)
    },
    // 修改
    amend(row) {
      this.$router.push({
        name: 'diandi-place-room-list-update',
        params: {
          id: row.id,
          rowData: row
        }
      })
    },
    // 房态维护
    status(row) {
      this.$router.push({
        name: 'diandi-place-room-room-status-index',
        params: {
          id: row.id,
          rowData: row
        }
      })
    },
    // 房价维护
    price(row) {
      this.$router.push({
        name: '/diandi_place/room/room-price/index.vue',
        params: {
          id: row.id,
          rowData: row
        }
      })
    },
    handleCreate() {
      this.$router.push({
        name: 'diandi-place-room-list-create'
      })
    },
    // 删除
    delectRow(row) {
      const that = this
      roomDelete(row.id).then((response) => {
        that.dialogFormVisible = false
        if (response.code === 200) {
          this.$message.success(response.message)
          that.getList()
        } else {
          this.$message.error(response.message)
        }
      })
    }
  }
}
</script>
<style scoped>
.active {
  color: #fff;
  background-color: #409eff;
}
.isActive {
  color: #fff;
  background-color: #9ca1a1;
}
</style>
s
